<?php

class ViewUser
{
	private $_user = null;
	
	public function __construct( $user )
	{
		if( !is_array( $user ) )
			$user = array( );
		
		$this ->_user = $user;
	}
	
	public function __get( $k )
	{
		if( $k == 'signed' )
			return !empty( $this ->_user );
		
		if( $k == 'somename' )
		{
			$names = array_filter( array_map( 'trim', array( $this ->fullname, $this ->nickname, $this ->login ) ) );
			return array_shift( $names );
		}
		
		if( !isset( $this ->_user[ $k ] ) )
			return null;
		
		return $this ->_user[ $k ];
	}
	
	public function __toString( )
	{
		if( empty( $this ->_user ) ) return '';
		
		return sprintf( '%s [%d]', $this ->somename, $this ->id );
	}
}
